package collection.list;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class StudentListTest {
    public static void main(String[] args) {
        List<Student> list = new ArrayList<>();
        list.add(new Student("czhangsan",11));
        list.add(new Student("alisi",12));
        list.add(new Student("dwangwu",13));
        list.add(new Student("bzhaoliu",19));
        list.add(new Student("eqianqi",10));
        list.sort(new Comparator<Student>(){
            @Override
            public int compare(Student o1, Student o2) {
//                return o1.getAge()-o2.getAge();
                return o1.getName().compareTo(o2.getName());
            }
        });
        for (Student student : list) {
            System.out.println("student = " + student);
        }

        System.out.println("=====================================");
        Collections.shuffle(list);
        for (Student student : list) {
            System.out.println("student = " + student);
        }

        System.out.println("=====================================");
        Collections.sort(list, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o1.getName().compareTo(o2.getName());
            }
        });
        for (Student student : list) {
            System.out.println("student = " + student);
        }
        System.out.println("=====================================");
        Collections.reverse(list);
        for (Student student : list) {
            System.out.println("student = " + student);
        }
    }
}
